package com.lujieni.springbootmybatis.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lujieni.springbootmybatis.dao.PersonDao;
import com.lujieni.springbootmybatis.dao.StudentDao;
import com.lujieni.springbootmybatis.po.PersonDO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：Jie Ni
 * @Date: 2025/6/16 9:15
 * @Description:
 */
@Service
@RequiredArgsConstructor
public class PersonServiceImpl implements IPersonService{

    private final PersonDao personDao;

    private final StudentDao studentDao;

    @Override
    public PersonDO getById(Long id) {
        return personDao.selectById(id);
    }

    @Override
    public Page<PersonDO> getPage(int current, int size) {
        Page<PersonDO> page = new Page<>(current, size);
        return personDao.selectPage(page, null);
    }

    @Override
    public void insert(PersonDO person) {
        personDao.insert(person);
    }

    @Override
    public IPage<PersonDO> selectByAge(IPage<PersonDO> page, String age) {
        List<PersonDO> result = personDao.selectByAge(page, age);
        page.setRecords(result);
        return page;
    }
}
